﻿using MediatR;
using T_Person.BaseRep.Interface;
using T_Person.Read.APi.Applaction.Command;
using T_Person.Read.APi.Dto;

namespace T_Person.Read.APi.Applaction.CommandHandlers
{
    public class EmployeeSearchBystateCommandHandlers : IRequestHandler<EmploySearchByStateCommand, List<EmployeeNameDto>>
    {
        private readonly IEmployeeRep employeeRep;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="employeeRep"></param>
        public EmployeeSearchBystateCommandHandlers(IEmployeeRep employeeRep)
        {
            this.employeeRep = employeeRep;
        }

        public async Task<List<EmployeeNameDto>> Handle(EmploySearchByStateCommand request, CancellationToken cancellationToken)
        {
            if (request.state>6)
            {
                var lista = await employeeRep.GetvaluesByResult(x => x.EmployeeStyle!=0 && x.IsDel.Equals(false));
                var listb = new List<EmployeeNameDto>();
                foreach (var item in lista)
                {
                    listb.Add(new EmployeeNameDto
                    {
                        id = item.Eid,
                        Name = item.Ename
                    });
                }
                return listb;
            }
            var list = await employeeRep.GetvaluesByResult(x => x.EmployeeStyle.Equals(request.state) && x.IsDel.Equals(false));
            var lists=new List<EmployeeNameDto>();
            foreach (var item in list)
            {
                lists.Add(new EmployeeNameDto
                {
                    id = item.Eid,
                    Name = item.Ename
                });
            }
            return lists;
        }
    }
}
